{include file="public/header" /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-inline layui-show-xs-block">
                    <button class="layui-btn layui-btn-normal" onclick="data_edit('添加','list_add')">添加</button>
                </div>
                <div class="layui-card-body ">

                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block" id="province">
                            <select name="province" data-area="" lay-search='' lay-filter="province">
                                <option value="">选择省份</option>
                                {foreach $province as $v}
                                <option value="{$v.area_code}" {if !empty(input('get.province')) &&
                                    input('get.province')==$v.area_code}selected{/if}>{$v.name}
                                </option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block" id="city">
                            <select name="city" data-area="" lay-search='' lay-filter="city">
                                <option value="">选择城市</option>
                                {foreach $city as $v}
                                <option value="{$v.area_code}" {if !empty(input('get.city')) &&
                                    input('get.city')==$v.area_code}selected{/if}>{$v.name}
                                </option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block" id="area">
                            <select name="area" data-area="" lay-search='' lay-filter="area">
                                <option value="">选择区域</option>
                                {foreach $area as $v}
                                <option value="{$v.area_code}" {if !empty(input('get.area')) &&
                                    input('get.area')==$v.area_code}selected{/if}>{$v.name}
                                </option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block" id="street">
                            <select name="street" data-area="" lay-search='' lay-filter="street">
                                <option value="">选择街道</option>
                                {foreach $street as $v}
                                <option value="{$v.id}" {if !empty(input('get.street')) &&
                                    input('get.street')==$v.id}selected{/if}>{$v.name}
                                </option>
                                {/foreach}
                            </select>
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="title" placeholder="备注查询" value="{:input('get.title')}"
                                autocomplete="off" class="layui-input">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="sreach">搜索</button>
                        </div>

                    </form>

                </div>

                <div class="layui-card-body layui-table-body layui-table-main">
                    <table class="layui-table layui-form">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>备注</th>
                                <th>类型</th>
                                <th>省份</th>
                                <th>城市</th>
                                <th>区域</th>
                                <th>街道</th>
                            </tr>
                        </thead>
                        <tbody>
                            {foreach $list as $v}
                            <tr>
                                <td>{$v.id}</td>
                                <td>{$v.nickname}</td>
                                <td>{if $v.type == 1}
                                    <button type="button" class="layui-btn-normal layui-btn layui-btn-sm">总管理员</button>
                                    {elseif $v.type == 2}
                                    <button type="button" class="layui-btn-warm layui-btn layui-btn-sm">城市合伙人</button>
                                    {elseif $v.type == 3}
                                    <button type="button" class="layui-btn layui-btn layui-btn-sm">区域合伙人</button>
                                    {elseif $v.type == 4}
                                    <button type="button" class="layui-btn layui-btn layui-btn-sm">街道合伙人</button>
                                    {else}
                                    {/if}
                                </td>
                                <td>{$v.province_text|default=""}</td>
                                <td>{$v.city_text|default=""}</td>
                                <td>{if !empty($v.area_text)}
                                    {foreach $v.area_text as $area}
                                    {$area.name}
                                    {/foreach}
                                    {/if}
                                </td>
                                <td>{if !empty($v.street_text)}
                                    {foreach $v.street_text as $street}
                                    {$street.name},
                                    {/foreach}
                                    {/if}
                                </td>
                            </tr>
                            {/foreach}

                        </tbody>
                    </table>
                </div>
                <div class="layui-card-body ">
                    <div class="page">
                        {$list->render()|raw}
                    </div>
                </div>

            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['form', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer
            , upload = layui.upload;
        //监听省份选择市区
        form.on('select(province)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 2 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择城市</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="city"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });

        form.on('select(city)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 3 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择区域</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.area_code;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="area"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });
        form.on('select(area)', function (data) {
            $.ajax({
                type: 'get',
                url: '/base/getarea',
                data: { id: data.value, level: 4 },
                success: function (res) {
                    if (res.code == 0 && data.value > 0) {
                        var str = '<option value="">请选择街道</option>';
                        $.each(res.data, function (i, obj) {
                            str += '<option value="' + obj.id;
                            str += '">' + obj.name;
                            str += '</option>';
                        });
                        $('select[name="street"]').html(str);
                        form.render();
                    }
                }
            });
            return false;
        });
    });

</script>
{include file="public/footer"}